const { sequelize } = require("../db/index")
const { DataTypes, Model } = require("sequelize")
const User = require("./user_model")
const Cleaner = require("./cleaner_model")
const moment = require("moment")

class OrderGoods extends Model {
  static async hasCate(id) {
    const cate = await Cate.findOne({ where: { id } })
    if (cate === null) {
      return false
    } else {
      return true
    }
  }
}
OrderGoods.init(
  {

    order_id: {
      comment: "订单id",
      type: DataTypes.INTEGER,
      allowNull: false
    },
    // order_no: {
    //   comment: "订单号",
    //   type: DataTypes.STRING,
    //   allowNull: false
    // },
    // goods_id: {
    //   comment: "商品id",
    //   type: DataTypes.INTEGER,
    //   allowNull: false
    // },
    sku_id: {
      comment: "商品规格id",
      type: DataTypes.INTEGER,
      allowNull: false
    },
    goods_name: {
      comment: "商品名称",
      type: DataTypes.STRING,
      allowNull: false
    },
    sku: {
      comment: "商品规格",
      type: DataTypes.STRING,
      allowNull: false
    },
    order_type: {
      comment: "订单类型",
      type: DataTypes.INTEGER,
      allowNull: false
    },
    store_house_id: {
      comment: "出货仓库ID",
      type: DataTypes.INTEGER,
      allowNull: false
    },
    goods_num: {  // sales
      comment: "商品数量",
      type: DataTypes.INTEGER,
      allowNull: false
    },
    goods_price: {
      comment: "单价",
      type: DataTypes.DECIMAL,
      allowNull: false
    },
    discount: {
      comment: "折扣",
      type: DataTypes.DECIMAL,
      allowNull: false  
    },
    discount_price: {
      comment: "折后单价",
      type: DataTypes.DECIMAL,
      allowNull: false
    },
    remarks: {
      comment: "备注",
      type: DataTypes.STRING,
      allowNull: true
    },
    // config: {
    //   comment: "商品其他数据",
    //   type: DataTypes.STRING,
    //   allowNull: true
    // },
    create_time: {
      comment: "创建时间",
      type: DataTypes.DATE,
      get() {
        return moment(this.getDataValue("update_time")).format(
          "YYYY-MM-DD HH:mm:ss"
        )
      }
    },
    update_time: {
      comment: "更新时间",
      type: DataTypes.STRING,
      get() {
        return moment(this.getDataValue("update_time")).format(
          "YYYY-MM-DD HH:mm:ss"
        )
      }
    }
  },
  {
    sequelize,
    modelName: "sp_store_order_goods",
    freezeTableName: true,
    paranoid: false,
    timestamps: false
  }
)

OrderGoods.removeAttribute("id")

module.exports = OrderGoods
